1. Using modelflow with World Bank models#

The Modelflow python package has been developed to solve a wide range of models, see the modelflow github web site for working examples of the Solow Model, the United States’ Federal REserve FR/USB model and others.

The package has been substantially expanded to include special features that enable it to work with World Bank models originally developed in EViews and designed to use the EViews Model Object for simulation.

This chapter illustrates how to access these models, how to load them into a modelflow anaconda environment on your computer, and how to perform a variety of simulations.

Warning

To be updated when final storage for models is sorted.

1.1. Publicly available World Bank models that run under modelflow#

At this time several World bank macrostructural models are available to download and use with modelflow. These include a macrostructural model for:

  • Indonesia (Climate features)

  • Nepal (Climate features)

  • Croatia (Quarterly model)

  • Iraq (Standard Macro-fiscal model)

  • Uganda (Annual model with climate features)

  • Bolivia (Annual Model)

  • Pakistan (Annual model with climate features)

Each of these models has been developed as part of the outreach work of the World Bank. The basic modelling framework of each of these models is outlined in Burns et al. [2019] with specific extensions reflecting features of the individual country modelled. The basic approach for the models with climate features is laid out in Burns et al. [2021], although several additional features are included in some of these models that has not yet been documented.

As additional models are released they will be made available using the mechanism described below.

The examples in this book use the Pakistan model.

1.2. How to access the models#

A user who has installed the modeflflow library will have access to the .load_repo+widget which can be executed with the following code:

model.load_repo_widget(loadspec,destination='./wbmodels') # and be changed to for instance model.select_wb_models

This will invoke a dialog listing all of the World Bank models available at this time. To download and install a model on your system, one needs only select the model you want to work with and press the submit button.

The models are distributed in as github repositories (repos) when the submit button is pressed the selected countries will be downloaded to the local computer. Each repo contains the model, data and notebooks which will work with the model and data. The user can use these notebooks for analysis or as starting point for additional analysis.

#This is for testing until we have all models in github repos
import yaml
loadspec = yaml.safe_load(open('../../repo_def.yaml','r'))
print(loadspec)
[{'description': '-- WB country models', 'repo_name': 'nnn'}, {'description': 'Pakistan model', 'repo_name': 'pak'}, {'description': 'Pakistan model version 2', 'repo_name': 'pak'}, {'repo_name': 'pak'}, {'description': '--- FTT models', 'repo_name': 'xxx'}, {'repo_name': 'FTT-Modelflow', 'owner': 'fdenning'}]
model.load_repo_widget(loadspec,destination='./wbmodels') # and be changed to for instance model.select_wb_models
Select github repo to download

When the submit button is pressed, the github repos which has been selected is downloaded, and the notebooks present will be displayed like this.

Menu to start notebooks in subfolders

Note

The default download location is wbmodels\. The download location can be changed by setting the parameter destination= to another location.

Warning

A repo can only be downloaded once. If a repo has already has been downloaded, and a user wants to download it a second time they will have to first delete or move the already downloaded version.

1.3. .display_toc() Displayed a list of the notebooks in current work folder and all subfolders.#

This this can be used if the user want to display the list of notebooks after the repo has been selected.

try:
    model.display_toc("..\models")
except:
    print("Failed to display model inventory from requested location")
    
Failed to display model inventory from requested location

2. To do list#

This JN needs to be finished. Need to

  1. decide on a temporary home for models;

  2. have that home as part of the default in the widget but allow it to be overridden;

  3. the display_toc needs to be better documented, notably as to where the user is going to have their models saved on their personal machines and how they can customize that and tell the display_toc where to find them.

Finally not clear why we have to delete, why cannot user overwrite a repo that was already downloaded?